﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _04_04_Directory文件夹类操作
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = folderBrowserDialog.SelectedPath;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBox2.Text = folderBrowserDialog.SelectedPath;

            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (Directory.Exists(this.textBox1.Text) && Directory.Exists(this.textBox2.Text))
            {
                string[] temp = this.textBox1.Text.Split('\\');
                string Path = this.textBox2.Text + '\\' + temp[temp.Length - 1];

                if (Directory.Exists(Path))
                {
                    DialogResult dr = MessageBox.Show("目标文件夹已存在，是否覆盖", "提示: ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        Directory.Delete(Path, true);
                        Directory.Move(this.textBox1.Text, Path);
                        MessageBox.Show("移动成功");
                        return;
                    }
                }

                Directory.Move(this.textBox1.Text, Path);
                MessageBox.Show("移动成功");

            }

            else
            {
                MessageBox.Show("文件夹不存在");
                return;
            }
        }

        //删除文件夹
        private void button5_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(this.textBox1.Text))
            {
                MessageBox.Show("文件夹不存在");
                return;
            }
            Directory.Delete(this.textBox1.Text, true);
            MessageBox.Show("文件夹删除成功");
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
